package su.samcom.calc.model.dao;

import org.springframework.stereotype.Repository;
import su.samcom.calc.model.entity.Country;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Владислав
 * Date: 24.11.13
 * Time: 12:41
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class CountryDaoImpl extends BaseDaoImpl<Country> implements CountryDao {

    @Override
    protected Class<Country> getGeneric() {
        return Country.class;
    }

    @Override
    public List<Country> getLikeCountries(String name) {
        String sql = "from Country c where lower(c.name) like lower(:name)";
        List<Country> countries = sessionFactory.getCurrentSession().createQuery(sql)
                .setParameter("name", String.format("%s%%", name)).list();
        return countries;
    }
}
